from selenium.webdriver.common.by import By

from base.base_action import BaseAction


class ContactPage(BaseAction):

    username_label = By.XPATH, "//*[@text='姓名']"
    mobile_label = By.XPATH, "//*[@text='电话']"
    back_button_label = By.XPATH, "//*[@content-desc='向上导航']"
    mobile_text_label = By.ID, "com.android.contacts:id/header"

    def input_username(self, username):
        """
        输入用户名
        :return:
        """
        self.send_keys(self.username_label, username)

    def input_mobile(self, mobile):
        """
        输入电话
        :return:
        """
        self.send_keys(self.mobile_label, mobile)

    def click_back_button(self):
        """
        点击后退
        :return:
        """
        self.click(self.back_button_label)

    def get_mobile(self):
        """
        获取手机号
        :return:
        """
        mobile = self.get_text(self.mobile_text_label)
        return mobile.replace(" ", "")